package com.example.fish.service.little;

import com.example.fish.mapper.*;
import com.example.fish.pojo.BlogExample;
import com.example.fish.pojo.EventExample;
import com.example.fish.pojo.SecretExample;
import com.example.fish.pojo.UserInfo;
import com.example.fish.vo.AuthorInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LittleService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private RaceMapper raceMapper;
    @Autowired
    private BlogMapper blogMapper;
    @Autowired
    private EventMapper eventMapper;
    @Autowired
    private SecretMapper secretMapper;
    /***
     * 高手秘籍的作者信息
     */

    public AuthorInfo getAuthorInfo(Integer userid){
//        获取动态数
        BlogExample blogExample = new BlogExample();
        blogExample.createCriteria().andUseridEqualTo(userid);
        int blogCount = blogMapper.countByExample(blogExample);
//        获取秘籍数
        SecretExample secretExample = new SecretExample();
        secretExample.createCriteria().andUseridEqualTo(userid);
        int secretCount = secretMapper.countByExample(secretExample);
//        获取活动数
        EventExample eventExample = new EventExample();
        eventExample.createCriteria().andUseridEqualTo(userid);
        int eventCount = eventMapper.countByExample(eventExample);
//        获取用户信息
        UserInfo userInfo = userInfoMapper.selectByPrimaryKey(userid);
        AuthorInfo authorInfo = new AuthorInfo();
        authorInfo.setUserid(userid);
        authorInfo.setUsername(userInfo.getName());
        authorInfo.setAvatar(userInfo.getAvator());
        authorInfo.setFishage(userInfo.getFishage());
        authorInfo.setBlogCount(blogCount);
        authorInfo.setEventCount(eventCount);
        authorInfo.setSecretCount(secretCount);
        return authorInfo;
    }

}
